<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\DB;

class CreateMenuTable extends Migration
{
    /**
     * run migrate
     * 运行迁移应用
     */
    public function up(){
        Schema::Create('menu', function(Blueprint $table){
            $table->engine = 'InnoDB';
            $table->charset = 'utf8mb4';
            $table->collation = 'utf8mb4_general_ci';

            $table->increments('id')->comment('主键');
            $table->unsignedInteger('father_id')->nullable(true)->comment('父ID');
            $table->string('name', 255)->nullable(false)->comment('菜单名称');
            $table->string('icon', 255)->nullable(true)->comment('菜单icon图标');
            $table->string('path', 6400)->nullable(true)->comment('父ID路径');
            $table->string('url', 255)->nullable(true)->comment('跳转url');
            $table->unsignedTinyInteger('is_show')->nullable(true)->default(0)->comment('是否显示：0否，1是，默认为0');
            $table->unsignedSmallInteger('row_num')->nullable(true)->default(0)->comment('排序顺序');
            $table->tinyInteger('level')->unsigned()->nullable(true)->default(1)->comment('级别：默认为1级');
            $table->dateTime('updated_at')->nullable(true)->comment('修改时间');
            $table->dateTime('created_at')->nullable(true)->comment('建立时间');

            $table->index('father_id', 'father_id');
            $table->index('url', 'url');
        });
        DB::statement("ALTER TABLE `menu` comment '后台菜单'");
    }

    /**
     * reset migrate
     * 运行回滚时应用
     */
    public function down(){
        Schema::dropIfExists('menu');
    }
}
